/**
 * Author: Shen Yanqiu
 * Date: 2017-12-06
 * Time: 11:54
 *
 */
import React from 'react';
import { routerRedux } from 'dva/router';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import { Page } from 'components';
import queryString from "query-string";
import { List, Operation } from './Components';
import { routerTool } from 'utils';
import TopRightButton from './../../components/TopOperation/TopRightButton';

class Expenditure extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    dispatch: PropTypes.func,
    expenditure: PropTypes.object,
    location: PropTypes.object,
  };
  render () {
    const { loading, location, expenditure, dispatch } = this.props;
    location.query = queryString.parse(location.search);
    const { list, pagination } = expenditure;
    const listProps = {
      dataSource: list,
      loading: loading.effects['expenditure/getExpenditureList'],
      pagination,

      onChange (_pagination) {
        const { query, pathname } = location;
        dispatch({
          type: 'expenditure/getExpenditureList',
          payload: {
            ...query,
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },

      onSeeItem (record) {
        dispatch({
          type: 'expenditure/onSeeItemModal',
          payload: {
            id: record.id,
          },
        });
      },

      onDeleteItem (id, record) {
        dispatch({
          type: 'expenditure/onDeleteItemModal',
          payload: {
            id: id,
          },
        });
      },

    };
    function SearchData (data) {
      dispatch({
        type: 'expenditure/searchData',
        payload: {
          formData: data,
        },
      });
    }
    function clickHandle () {
      dispatch(
        routerTool.redirectTo({
          name: 'AddExpenditure',
        })
      );
    }
    return (
      <Page loading={loading.models.expenditure} inner >
        <Operation SearchData={SearchData} />
        <List {...listProps} />
        <TopRightButton contentText="添加申请" clickHandle={clickHandle} />
      </Page>
    );
  }
}
export default connect(({ loading, expenditure }) => ({ loading, expenditure }))(Expenditure);
